#include <conio.h> 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h> 
#include <crtdbg.h> 
#include "stack.h"

void inputString(const char * prompt, char * input)
{
	input[0] = 0;
	printf("%s", prompt);
	scanf("%[^\n]", input);
	fflush(stdin);
}

int ord[8];
void init()
{
	int i;
	char * alpha = "([{<)]}>";
	for (i = 0; i < strlen(alpha); i++)
	{
		ord[alpha[i]] = i+1;
	}
}



int main()
{
	Stack STACK;
	char  line[10000];
	int sim, i, j, dlprv = 0;
	inputString("input string: ", line);
	init();
	//       assert(check_parentheses("(()") == 0);
	stack_create(&STACK);
	for (i=0; i<strlen(line); i++)
	{
		sim=ord[line[i]];
		if ((sim>=1)&&(sim<=4))
		{
			stack_push(&STACK, (pointer)sim);
		}
		if ((sim>=5)&&(sim<=8))
		{
			j=stack_pop(&STACK);
			if ((j == 0)||( j != sim-4))
			{
				dlprv=1;
				break;
			}
		}
	}
	if (dlprv == 1)
	{
		printf("balans ne cobluden\n");
		stack_destroy(&STACK);
		system ("PAUSE");
	}
	j=stack_pop(&STACK);
	if (j != 0)
	{
		printf("balans ne cobluden\n");
		stack_destroy(&STACK);
		system ("PAUSE");
	}
	if ((dlprv == 0)&&(j == 0))
	{
	printf("balans cobluden\n");
	stack_destroy(&STACK);
	system ("PAUSE");
	}

	_CrtDumpMemoryLeaks();
}